<?php
// no direct access
defined('_JEXEC') or die('Restricted access');
jimport('joomla.application.component.model');
JTable::addIncludePath(JPATH_COMPONENT.DS.'tables');

class SimplelistingModelControlpanel extends JModel {

    function getLatestEntries()
    {
        return 0;
    }

    function latestEntries( $count = 10)
    {
        $db = & JFactory::getDBO();

        $query = "SELECT a.*, u.name as `username`, ca.name as `category`, DATE_FORMAT( a.date_created, \"%D %M %Y\") AS entrydate "
         . " FROM ".$db->nameQuote('#__simplelisting')." as a "
         . " LEFT JOIN ".$db->nameQuote('#__simplelisting_categories')." AS ca ON ".$db->nameQuote('ca.id')."=".$db->nameQuote('a.category_id ')
         . " LEFT JOIN ".$db->nameQuote('#__users')." AS u ON u.id = a.create_by "
         . " LEFT JOIN ".$db->nameQuote('#__contact_details')." AS cd ON cd.user_id = a.create_by "
         . " ORDER BY date_created DESC LIMIT " . $count;
        $db->setQuery($query);
        $rows = $db->loadObjectList();
        return $rows;
    }


}
